﻿//////////////////////////////////////////////////////////////////////////////
//
// Copyright © 1998-2024 Glodon Company Limited.
//
// Licensed under the MIT License
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the “Software”),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
//////////////////////////////////////////////////////////////////////////////
#include "AddPageStructure.h"
#include "StructureRibbonControlIds.h"
#include "StructureCmdIds.h"
#include "GbmpUiPlatformCommandIds.h"
#include "GcmpCommandNames.h"
#include "IRibbon.h"
#include "IRibbonPage.h"
#include "IRibbonGroup.h"
#include "IApplication.h"
#include "IMainWindow.h"
#include "ICommandButtonMenuDefinition.h"
#include "ICommandMenuItemDefinition.h"
#include "ICommandButtonDefinition.h"
#include "IPageHandler.h"
#include "CmdStatusUtils.h"

#include "EnableCompileWarning_The_LAST_IncludeInCpp.h"
using namespace gcmp;

namespace
{
    class StructurePageHandler : public IPageHandler
    {
    public:
        StructurePageHandler() {}
        virtual bool IsVisible() const override
        {
            CMD_ONLY_VISIBLE_IN_PROJECT_ENVIRONMENT;
        }
        virtual bool IsEnabled() const override
        {
            return true;
        }
    };

}

void AddPageStructure::AddStructurePages()
{
    OwnerPtr<IRibbonPage> opPage = IRibbonPage::Create(ID_PAGE_STRUCTURE, GBMP_TR(L"结构建模"));
    DBG_WARN_AND_RETURN_VOID_UNLESS(opPage, L"opPage为空",L"GDMPLab",L"2024-03-30");
    opPage->SetPageHandler(TransferOwnership(NEW_AS_OWNER_PTR(StructurePageHandler)));

    // 上部结构Group
    {
        const std::wstring groupTempId = L"上部结构";
        OwnerPtr<IRibbonGroup> opGroup = IRibbonGroup::Create(groupTempId, GBMP_TR(groupTempId));
        DBG_WARN_AND_RETURN_VOID_UNLESS(opGroup, L"opGroup为空",L"GDMPLab",L"2024-03-30");

        { // 结构墙
            const std::wstring buttonMenuId = L"gmStructureWallMenu";
            OwnerPtr<ICommandButtonMenuDefinition> opButtonMenuDef = ICommandButtonMenuDefinition::Create(buttonMenuId, ID_CMD_DRAW_STRUCTURE_STRAIGHT_WALL, GBMP_TR(L"结构墙"), L":/images/create_model_wall.png");
            DBG_WARN_AND_RETURN_VOID_UNLESS(opButtonMenuDef, L"opButtonMenuDef为空",L"GDMPLab",L"2024-03-30");

            {
                OwnerPtr<ICommandMenuItemDefinition> opMenuItem = ICommandMenuItemDefinition::Create(ID_CMD_DRAW_STRUCTURE_STRAIGHT_WALL, ID_CMD_DRAW_STRUCTURE_STRAIGHT_WALL, GBMP_TR(L"基本剪力墙"), GBMP_TR(L"基本剪力墙"), L":/images/create_model_wall.png");
                opButtonMenuDef->AddItem(TransferOwnership(opMenuItem));
            }
            {
                OwnerPtr<ICommandMenuItemDefinition> opMenuItem = ICommandMenuItemDefinition::Create(ID_CMD_DRAW_VARIABLE_SECTION_STRUCTURE_STRAIGHT_WALL, ID_CMD_DRAW_VARIABLE_SECTION_STRUCTURE_STRAIGHT_WALL, GBMP_TR(L"变截面墙"), GBMP_TR(L"变截面墙"), L":/images/create_model_variable_section_wall.png");
                opButtonMenuDef->AddItem(TransferOwnership(opMenuItem));
            }

            opGroup->AddButtonMenu(TransferOwnership(opButtonMenuDef));
        }
        {
            // 结构梁
            const std::wstring buttonMenuId = L"gmStructureBeamMenu";
            OwnerPtr<ICommandButtonMenuDefinition> opButtonMenuDef = ICommandButtonMenuDefinition::Create(buttonMenuId, ID_CMD_CREATE_STRAIGHT_STRUCTURE_BEAM, GBMP_TR(L"结构梁"), L":/images/structure/Beam.png", GBMP_TR(L"结构梁"));
            DBG_WARN_AND_RETURN_VOID_UNLESS(opButtonMenuDef, L"opButtonMenuDef为空",L"GDMPLab",L"2024-03-30");

            {
                OwnerPtr<ICommandMenuItemDefinition> opMenuItem = ICommandMenuItemDefinition::Create(ID_CMD_CREATE_STRAIGHT_STRUCTURE_BEAM, ID_CMD_CREATE_STRAIGHT_STRUCTURE_BEAM, GBMP_TR(L"基本梁"), GBMP_TR(L"基本梁"), L":/images/structure/Beam.png");
                opButtonMenuDef->AddItem(TransferOwnership(opMenuItem));
            }
            {
                OwnerPtr<ICommandMenuItemDefinition> opMenuItem = ICommandMenuItemDefinition::Create(ID_CMD_CREATE_STRAIGHT_STRUCTURE_VARIABLE_SECTION_BEAM, ID_CMD_CREATE_STRAIGHT_STRUCTURE_VARIABLE_SECTION_BEAM, GBMP_TR(L"变截面梁"), GBMP_TR(L"变截面梁"), L":/images/structure/VariableSectionBeam.png");
                opButtonMenuDef->AddItem(TransferOwnership(opMenuItem));
            }
            {
                OwnerPtr<ICommandMenuItemDefinition> opMenuItem = ICommandMenuItemDefinition::Create(ID_CMD_CREATE_STRAIGHT_STRUCTURE_CUSTOMIZED_PROFILE_BEAM_FAMILY_DOCUMENT, ID_CMD_CREATE_STRAIGHT_STRUCTURE_CUSTOMIZED_PROFILE_BEAM_FAMILY_DOCUMENT, GBMP_TR(L"自定义截面梁"), GBMP_TR(L"自定义截面梁"), L":/images/structure/CustomizedProfileBeam.png");
                opButtonMenuDef->AddItem(TransferOwnership(opMenuItem));
            }
            opGroup->AddButtonMenu(TransferOwnership(opButtonMenuDef));
        }
        {
            // 结构板
            const std::wstring buttonMenuId = L"gmStructureFloorMenu";
            OwnerPtr<ICommandButtonMenuDefinition> opButtonMenuDef = ICommandButtonMenuDefinition::Create(buttonMenuId, ID_CMD_CREATE_STRUCTURE_FLOOR, GBMP_TR(L"结构板"), L":/images/create_model_floor.png");
            DBG_WARN_AND_RETURN_VOID_UNLESS(opButtonMenuDef, L"opButtonMenuDef为空",L"GDMPLab",L"2024-03-30");
            {
                OwnerPtr<ICommandMenuItemDefinition> opMenuItem = ICommandMenuItemDefinition::Create(ID_CMD_CREATE_STRUCTURE_FLOOR, ID_CMD_CREATE_STRUCTURE_FLOOR, GBMP_TR(L"结构板"), GBMP_TR(L"结构板"), L":/images/create_model_floor.png");
                opButtonMenuDef->AddItem(TransferOwnership(opMenuItem));
            }
            {
                OwnerPtr<ICommandMenuItemDefinition> opMenuItem = ICommandMenuItemDefinition::Create(ID_CMD_AUTO_RECGNIZE_STRUCTURE_FLOOR, ID_CMD_AUTO_RECGNIZE_STRUCTURE_FLOOR, GBMP_TR(L"自动识别楼板"), GBMP_TR(L"自动识别楼板"), L":/images/structure/结构建模_楼板_自动识别楼板.png");
                opButtonMenuDef->AddItem(TransferOwnership(opMenuItem));
            }
            opGroup->AddButtonMenu(TransferOwnership(opButtonMenuDef));
        }
        { // 结构柱
            const std::wstring buttonMenuId = L"gmStructureColumnMenu";
            OwnerPtr<ICommandButtonMenuDefinition> opButtonMenuDef = ICommandButtonMenuDefinition::Create(buttonMenuId, ID_CMD_DRAW_STRUCTURE_VERTICAL_COLUMN, GBMP_TR(L"结构柱"), L":/images/verticalColumn.png");
            DBG_WARN_AND_RETURN_VOID_UNLESS(opButtonMenuDef, L"opButtonMenuDef为空",L"GDMPLab",L"2024-03-30");

            {
                OwnerPtr<ICommandMenuItemDefinition> opMenuItem = ICommandMenuItemDefinition::Create(ID_CMD_DRAW_STRUCTURE_VERTICAL_COLUMN, ID_CMD_DRAW_STRUCTURE_VERTICAL_COLUMN, GBMP_TR(L"现浇混凝土柱"), GBMP_TR(L"现浇混凝土柱"), L":/images/verticalColumn.png");
                opButtonMenuDef->AddItem(TransferOwnership(opMenuItem));
            }

            {
                OwnerPtr<ICommandMenuItemDefinition> opMenuItem = ICommandMenuItemDefinition::Create(ID_CMD_DRAW_STRUCTURE_CUSTOMIZED_PROFILE_COLUMN_FAMILY_DOCUMENT, ID_CMD_DRAW_STRUCTURE_CUSTOMIZED_PROFILE_COLUMN_FAMILY_DOCUMENT, GBMP_TR(L"自定义截面柱"), GBMP_TR(L"自定义截面柱"), L":/images/slantedColumn.png");
                opButtonMenuDef->AddItem(TransferOwnership(opMenuItem));
            }

            opGroup->AddButtonMenu(TransferOwnership(opButtonMenuDef));
        }
        {
            // 屋顶
            OwnerPtr<ICommandButtonDefinition> opButtonDef = ICommandButtonDefinition::Create(ID_CMD_CREATE_STRUCTURE_ROOF, GBMP_TR(L"屋顶"), GBMP_TR(L"屋顶"), ID_CMD_CREATE_STRUCTURE_ROOF, L":/images/create_model_roof.png");
            opGroup->AddButton(TransferOwnership(opButtonDef));
        }
        opPage->AddGroup(TransferOwnership(opGroup));
    }

    // 基础Group
    {
        const std::wstring groupTempId = L"基础";
        OwnerPtr<IRibbonGroup> opGroup = IRibbonGroup::Create(groupTempId, GBMP_TR(groupTempId));
        DBG_WARN_AND_RETURN_VOID_UNLESS(opGroup, L"opGroup为空",L"GDMPLab",L"2024-03-30");

        {
            //筏板基础
            OwnerPtr<ICommandButtonDefinition> opButtonDef = ICommandButtonDefinition::Create(ID_CMD_CREATE_RAFT_FOUNDATION, GBMP_TR(L"筏板基础"), GBMP_TR(L"筏板基础"), ID_CMD_CREATE_RAFT_FOUNDATION, L":/images/create_model_raft_foundation.png");
            opGroup->AddButton(TransferOwnership(opButtonDef));
        }
        {
            //条形基础
            OwnerPtr<ICommandButtonDefinition> opButtonDef = ICommandButtonDefinition::Create(ID_CMD_CREATE_STRAIGHT_STRUCTURE_STRIP_FOUNDATION, GBMP_TR(L"条形基础"), GBMP_TR(L"条形基础"), ID_CMD_CREATE_STRAIGHT_STRUCTURE_STRIP_FOUNDATION, L":/images/structure/Beam.png");
            opGroup->AddButton(TransferOwnership(opButtonDef));
        }

        opPage->AddGroup(TransferOwnership(opGroup));
    }

    // 洞口Group
    {
        const std::wstring groupTempId = L"洞口";
        OwnerPtr<IRibbonGroup> opGroup = IRibbonGroup::Create(groupTempId, GBMP_TR(groupTempId));
        DBG_WARN_AND_RETURN_VOID_UNLESS(opGroup, L"opGroup为空",L"GDMPLab",L"2024-03-30");

        { // 结构墙洞
            OwnerPtr<ICommandButtonDefinition> opButtonDef = ICommandButtonDefinition::Create(ID_CMD_DRAW_RECT_STRUCTURE_WALL_HOLE, GBMP_TR(L"墙洞"), GBMP_TR(L"墙洞"), ID_CMD_DRAW_RECT_STRUCTURE_WALL_HOLE, L":/images/wall_opening.png");
            opGroup->AddButton(TransferOwnership(opButtonDef));
        }
        {
            //板洞
            OwnerPtr<ICommandButtonDefinition> opButtonDef = ICommandButtonDefinition::Create(ID_CMD_CREATE_STRUCTURE_PLATE_HOLE, GBMP_TR(L"板洞"), GBMP_TR(L"板洞"), ID_CMD_CREATE_STRUCTURE_PLATE_HOLE, L":/images/create_model_plate_hole.png");
            opGroup->AddButton(TransferOwnership(opButtonDef));
        }
        {
            //窗
            //OwnerPtr<ICommandButtonDefinition> opButtonDef = ICommandButtonDefinition::Create(ID_CMD_FAMILY_DRAW_WINDOW, GBMP_TR(L"窗"), GBMP_TR(L"窗"), ID_CMD_FAMILY_DRAW_WINDOW, L":/images/create_model_plate_hole.png");
            //opGroup->AddButton(TransferOwnership(opButtonDef));
        }
        opPage->AddGroup(TransferOwnership(opGroup));
    }

    // 定位件
    {
        const std::wstring groupTempId = L"定位件";
        OwnerPtr<IRibbonGroup> opGroup = IRibbonGroup::Create(groupTempId, GBMP_TR(groupTempId));
        DBG_WARN_AND_RETURN_VOID_UNLESS(opGroup, L"opGroup为空",L"GDMPLab",L"2024-03-30");

        { // 模型线
            OwnerPtr<ICommandButtonDefinition> opButtonDef = ICommandButtonDefinition::Create(ID_CMD_GBMP_DRAW_STRAIGHT_MODEL_LINE, GBMP_TR(L"模型线"), GBMP_TR(L"模型线"), ID_CMD_GBMP_DRAW_STRAIGHT_MODEL_LINE, L":/images/line.png");
            opGroup->AddButton(TransferOwnership(opButtonDef));
        }
        { // 模型线
            OwnerPtr<ICommandButtonDefinition> opButtonDef = ICommandButtonDefinition::Create(ID_CMD_GBMP_DRAW_STRAIGHT_MODEL_LINE_WITHOUT_REF, GBMP_TR(L"无关联模型线"), GBMP_TR(L"无关联模型线模型线"), ID_CMD_GBMP_DRAW_STRAIGHT_MODEL_LINE_WITHOUT_REF, L":/images/line.png");
            opGroup->AddButton(TransferOwnership(opButtonDef));
        }
        {
            OwnerPtr<ICommandButtonDefinition> opButtonDef = ICommandButtonDefinition::Create(ID_COM_DRAW_STRUCTURE_REFERENCEPLANE_BY_LINE, GBMP_TR(L"参照平面"), GBMP_TR(L"参照平面"), ID_COM_DRAW_STRUCTURE_REFERENCEPLANE_BY_LINE, L":/images/ref_plane.png");
            opGroup->AddButton(TransferOwnership(opButtonDef));
        }
        { // 轴网
            OwnerPtr<ICommandButtonDefinition> opButtonDef = ICommandButtonDefinition::Create(ID_CMD_DRAWING_LINE_GRIDNEW, GBMP_TR(L"轴网"), GBMP_TR(L"轴网"), ID_CMD_DRAWING_LINE_GRIDNEW, L":/images/create_grid.png");
            opGroup->AddButton(TransferOwnership(opButtonDef));
        }
        { // 楼层管理
            OwnerPtr<ICommandButtonDefinition> opButtonDef = ICommandButtonDefinition::Create(ID_CMD_MANAGE_STOREY, GBMP_TR(L"楼层管理"), GBMP_TR(L"楼层管理"), ID_CMD_MANAGE_STOREY, L":/images/structure/manage_storey.png");
            opGroup->AddButton(TransferOwnership(opButtonDef));
        }
        { // 参照标高
            OwnerPtr<ICommandButtonDefinition> opButtonDef = ICommandButtonDefinition::Create(ID_CMD_DRAWING_NEWLEVEL, GBMP_TR(L"参照标高"), GBMP_TR(L"参照标高"), ID_CMD_DRAWING_NEWLEVEL, L":/images/structure/level.png");
            opGroup->AddButton(TransferOwnership(opButtonDef));
        }
        opPage->AddGroup(TransferOwnership(opGroup));
    }

    // 工作平面Group
    {
        const std::wstring groupId(L"gbmpWorkplaneGroup");
        OwnerPtr<IRibbonGroup> opGroup = IRibbonGroup::Create(groupId, GBMP_TR(L"工作平面"));
        DBG_WARN_AND_RETURN_VOID_UNLESS(opGroup, L"opGroup为空",L"GDMPLab",L"2024-03-30");

        {
            OwnerPtr<ICommandButtonDefinition> opButtonDef = ICommandButtonDefinition::Create(ID_CMD_GBMP_SETUP_WORK_PLANE_BY_PICK, GBMP_TR(L"拾取选定\n工作平面"), GBMP_TR(L"拾取选定\n工作平面"), ID_CMD_GBMP_SETUP_WORK_PLANE_BY_PICK, L":/images/work_plane.png");
            opGroup->AddButton(TransferOwnership(opButtonDef));
        }
        {
            OwnerPtr<ICommandButtonDefinition> opButtonDef = ICommandButtonDefinition::Create(ID_CMD_GBMP_SETUP_WORK_PLANE, GBMP_TR(L"设置平面"), GBMP_TR(L"设置平面"), ID_CMD_GBMP_SETUP_WORK_PLANE, L":/images/work_plane.png");
            opGroup->AddButton(TransferOwnership(opButtonDef));
        }
        {
            OwnerPtr<ICommandButtonDefinition> opButtonDef = ICommandButtonDefinition::Create(ID_CMD_SHOW_HIDE_WORK_PLANE, GBMP_TR(L"显示平面"), GBMP_TR(L"显示平面"), ID_CMD_SHOW_HIDE_WORK_PLANE, L":/images/workplane_off.png");
            opGroup->AddButton(TransferOwnership(opButtonDef));
        }
        {
            OwnerPtr<ICommandButtonDefinition> opButtonDef = ICommandButtonDefinition::Create(ID_CMD_GBMP_USERCOORDSYSTEM_MGR, GBMP_TR(L"用户坐标系管理"), GBMP_TR(L"用户坐标系管理"), ID_CMD_GBMP_USERCOORDSYSTEM_MGR, L":/images/work_plane.png");
            opGroup->AddButton(TransferOwnership(opButtonDef));
        }
        opPage->AddGroup(TransferOwnership(opGroup));
    }

    IRibbon* pRibbon = IMainWindow::GetMainWindow()->GetRibbon();
    DBG_WARN_AND_RETURN_VOID_UNLESS(pRibbon, L"pRibbon为空",L"GDMPLab",L"2024-03-30");

    pRibbon->AddPage(TransferOwnership(opPage));
}

void AddPageStructure::DeleteStructurePages()
{
    IRibbon* pRibbon = IMainWindow::GetMainWindow()->GetRibbon();
    DBG_WARN_AND_RETURN_VOID_UNLESS(pRibbon, L"pRibbon为空",L"GDMPLab",L"2024-03-30");

    if (pRibbon->GetPage(ID_PAGE_STRUCTURE))
    {
        pRibbon->DeletePage(ID_PAGE_STRUCTURE);
    }
}
